﻿using System.ServiceModel;

using TraceView.Shared;
using TraceView.UI.Entities;

namespace TraceView.Service
{
    [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.Single,
        UseSynchronizationContext = true)]
    public sealed class TraceService : ITraceService
    {
        private readonly IDisplayTrace _display;

        public TraceService(IDisplayTrace display)
        {
            _display = display;
        }

        void ITraceService.Trace(TraceData data)
        {
            RegisteredTraceHandler registeredTraceHandler = null;
            if (data.TraceObject != null)
                registeredTraceHandler = RegisteredTraceHandlers.Instance[data.TraceObject.Type];

            TraceItem traceItem = TraceItem.FromTraceData(data, registeredTraceHandler);
            _display.ShowTrace(traceItem);
        }
    }
}